﻿Imports MyDLL

Public Class Form18

    Dim Search As New MyDLL.Search

    Private Sub Form18_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        TextBox1.Text = Form1.TextBox13.Text
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Try
            Dim Directory As String = TextBox1.Text

            Search.SearchWithExt(Directory, My.Computer.FileSystem.SpecialDirectories.MyDocuments & "\XMLO\search.t.xml", ".xml", ".txt", ".rtf")

            Form13.Show()
            Form13.ComboBox1.SelectedItem = "My Documents"
            Form13.TextBox2.Text = "XMLO"
            Form13.TextBox3.Text = "search"
            Form13.Open()
            Form13.ViewTable()
        Catch ex As Exception
            MsgBox("Failure")
        End Try
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Try
            Dim ID As String = TextBox2.Text
            Dim data As XElement = XElement.Load(My.Computer.FileSystem.SpecialDirectories.MyDocuments & "\XMLO\search.t.xml")

            Dim full As XElement = _
                  <Root>
                      <%= From el In data.<result> _
                          Where el.Attribute("id") = ID _
                          Select el.<FullName> %>
                  </Root>

            Dim namext As XElement = _
                  <Root>
                      <%= From el In data.<result> _
                          Where el.Attribute("id") = ID _
                          Select el.<Name> %>
                  </Root>

            Dim dir As XElement = _
                  <Root>
                      <%= From el In data.<result> _
                          Where el.Attribute("id") = ID _
                          Select el.<Directory> %>
                  </Root>

            Dim ext As XElement = _
                          <Root>
                              <%= From el In data.<result> _
                                  Where el.Attribute("id") = ID _
                                  Select el.<Extension> %>
                          </Root>

            Dim FullNamet As String = full
            Dim Namet As String = namext
            Dim Directorys As String = dir
            Dim Directoryt As String = Directorys & "\"
            Dim Extensiont As String = ext

            If Extensiont = ".xml" Then

                Dim words As String = Namet
                Dim split As String() = words.Split(New [Char]() {"."c})


                Dim NameOnly As String = split(0)
                Dim Folder As String = Directoryt

                If split(1) = "xml" Then
                    Form1.CheckBox1.CheckState = CheckState.Checked
                    Form1.CheckBox7.CheckState = CheckState.Checked

                    Form1.TextBox3.Text = NameOnly
                    Form1.TextBox7.Text = Folder

                    Form13.Close()
                    Form14.Close()
                    Form1.Open()
                ElseIf split(1) = "t" Then
                    Form13.Close()
                    Form14.Close()

                    Form13.Show()
                    Form13.CheckBox7.CheckState = CheckState.Checked
                    Form13.TextBox3.Text = NameOnly
                    Form13.TextBox7.Text = Folder
                    Form13.Open()
                End If
            ElseIf Extensiont = ".rtf" Then
                Dim words As String = Namet
                Dim split As String() = words.Split(New [Char]() {"."c})

                Dim NameOnly As String = split(0)
                Dim Folder As String = Directoryt

                Form13.Close()
                Form14.Close()

                Form10.Show()
                Form10.CheckBox7.CheckState = CheckState.Checked
                Form10.TextBox3.Text = NameOnly
                Form10.TextBox7.Text = Folder
                Form10.OpenRtf()
            ElseIf Extensiont = ".txt" Then
                Dim words As String = Namet
                Dim split As String() = words.Split(New [Char]() {"."c})

                Dim NameOnly As String = split(0)
                Dim Folder As String = Directoryt

                Form13.Close()
                Form14.Close()

                Form10.Show()
                Form10.CheckBox7.CheckState = CheckState.Checked
                Form10.TextBox3.Text = NameOnly
                Form10.TextBox7.Text = Folder
                Form10.OpenTxt()
            End If
        Catch ex As Exception
            MsgBox("Failure")
        End Try
    End Sub

End Class